/*
 * @(#)TaskSubTasksPropertySection.java.java        0.00 2007/12/27
 */
package jp.ekasi.pms.ui.properties.tabbed.section;

import jp.ekasi.pms.model.ModelPackage;
import jp.ekasi.pms.ui.editors.GanttchartEditor;
import jp.ekasi.pms.ui.properties.tabbed.common.section.AbstractTablePropertySection;

import org.eclipse.emf.common.command.CompoundCommand;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.edit.command.AddCommand;
import org.eclipse.emf.edit.domain.EditingDomain;

/**
 * @author sumari.rutao@gamil.com
 */
public class TaskSubTasksPropertySection extends AbstractTablePropertySection {

	@Override
	protected EReference getFeature() {
		return ModelPackage.Literals.TASK__SUB_TASKS;
	}
	
	@Override
	protected void handleClickCreateObject() {
		EditingDomain editingDomain = ((GanttchartEditor) getPart())
				.getEditingDomain();
		
		Object newObject = createNewChild();
		
		CompoundCommand command = new CompoundCommand();
		
		AddCommand addToProjectCommand = (AddCommand) AddCommand.create(editingDomain,
				eObject.eGet(ModelPackage.Literals.TASK__PROJECT), 
				ModelPackage.Literals.PROJECT__TASK_LIST,
				newObject);
		command.append(addToProjectCommand);
		
		AddCommand addToTaskCommand = (AddCommand) AddCommand.create(editingDomain,
				eObject,
				getFeature(),
				newObject );
		command.append(addToTaskCommand);
		
		editingDomain.getCommandStack().execute(command);
		
		this.refresh();
	}

}
